package org.xhnews.charts;

import net.rim.device.api.ui.Manager;

public class XYChartManager extends Manager {
    int myHeight;
    int myWidth;
    
  public XYChartManager()
  {
    //Disable scrolling in this manager.
    super(Manager.NO_HORIZONTAL_SCROLL |
      Manager.NO_VERTICAL_SCROLL);
  }

  //Override sublayout.
  protected void sublayout(int width, int height) {
    XYChartField field;
    int x_pos=0, y_pos=0;

    //Loop thru total number of fields within
    //this manager. In our case only our chart Field will be here
    int numberOfFields = getFieldCount();

    for (int i = 0; i < numberOfFields; i++)
    {
      //Get the field. 
      field = (XYChartField)getField(i); 

      //Obtain the custom x and y coordinates for
      setPositionChild(field, field.getXCoord(), field.getYCoord());

      x_pos=field.getXCoord();
      y_pos=field.getYCoord();


      //Layout the field.
      layoutChild(field, field.getPreferredWidth(), field.getPreferredHeight());
      width = field.getPreferredWidth();
      height = field.getPreferredHeight();
      myHeight=field.getPreferredHeight();
      myWidth=field.getPreferredWidth();

    }
    //Set the manager's extent
    
       setExtent(width + x_pos, height + y_pos );
  }


  public int getPreferredWidth()
  {
    return myWidth;  
  }

  public int getPreferredHeight()
  {
    return myHeight ; 
  }
}
